package bom.example.common.utils;

import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Stream;

/**
 * @author X.I.O
 * @title: StringUtils
 * @projectName springboot
 * @description: TODO
 * @date 2021/10/27 10:22
 */
public class StringUtils {

    /**
     * 拼接绝大多数都能用的sql in 查询所用到的字符串
     * @param strings
     * @return
     */
    public static String sqlJoinString(List<String> strings){
        StringBuilder stringBuilder=new StringBuilder();
        if(strings==null || strings.size()==0){
            return stringBuilder.toString();
        }
        int size=strings.size();
        int end= size - 1;
        stringBuilder.append("(");
        for (int i = 0; i < size ; i++) {
            String s=strings.get(i);
            stringBuilder
                    .append("'")
                    .append(s)
                    .append("'");
            if(i!=end){
                stringBuilder
                        .append(",");
            }
        }
        stringBuilder.append(")");
        return stringBuilder.toString();
    }


    public static String StringFormart(List<String> strings,String separator){
        if(strings==null || strings.size()==0){
            return "";
        }
        StringJoiner stringJoiner=new StringJoiner(separator);
        for (int i = 0; i < strings.size(); i++) {
            String str=strings.get(i);
            stringJoiner.add(str);
        }
        return stringJoiner.toString();
    }


}
